<%@ page language="java" contentType="text/html; charset=utf-8"	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib tagdir="/WEB-INF/tags/sys" prefix="sys"%>
<%@ taglib uri="/WEB-INF/tlds/webui.tld" prefix="webui"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}"	scope="request" />

<webui:enum var="menuEnum" code="MenuEnum"/>

<webui:panel id="editInfo" styleClass="display-none">
	<webui:form id="editInfoForm" styleClass="form-horizontal">
		<input type="hidden" value="" id="editInfoId" name="id"/>
		<!--
		<webui:input styleClass="col-sm-12" labelClass="col-sm-2" inputClass="col-sm-10"
			label="网页名称" type="text" id="editInfoHeader" name="header">
			<webui:validator required="true"></webui:validator>
		</webui:input>
		-->
		<webui:input styleClass="col-sm-12" labelClass="col-sm-2" inputClass="col-sm-10"
			label="站点标题" type="text" id="editInfoTitle" name="title">
			<webui:validator required="true"></webui:validator>
		</webui:input>
		<webui:input styleClass="col-sm-12" labelClass="col-sm-2" inputClass="col-sm-10"
			label="站点副标题(简称)" type="text" id="editInfoSubTitle" name="subTitle">
			<webui:validator required="true"></webui:validator>
		</webui:input>
		<webui:input styleClass="col-sm-12" labelClass="col-sm-2" inputClass="col-sm-10"
			label="版权描述" type="text" id="editInfoCopyright" name="copyright">
			<webui:validator required="true"></webui:validator>
		</webui:input>
		<webui:select styleClass="col-sm-12" labelClass="col-sm-2" inputClass="col-sm-10"
		 	label="默认导航" placeholder="请选择默认导航"
			id="editInfoDefaultNav" name="defaultNav" lookup="${menuEnum}">
			<webui:validator selected="true"></webui:validator>
		</webui:select>
		<webui:input styleClass="col-sm-12 display-none" labelClass="col-sm-2" inputClass="col-sm-9"
			label="FAV图标" id="editInfoFaviconFile"
			type="file"	name="faviconFile" placeholder="请选择新FAV图标">
		</webui:input>
		<webui:input label="ICON" id="editInfoIconFile"
			labelClass="col-sm-2" inputClass="col-sm-9"
			type="file"	name="iconFile" placeholder="请选择新ICON">
		</webui:input>
		<webui:input label="LOGO" id="editInfoLogoFile"
			labelClass="col-sm-2" inputClass="col-sm-9"
			type="file"	name="logoFile" placeholder="请选择新LOGO">
		</webui:input>
	</webui:form>
	<div class="col-md-8 pull-right">
		<webui:button type="button" buttonClass="btn-white" onclick="cancelInfo()">取消</webui:button>
		<webui:button id="editInfoSaveBtn" type="button" buttonClass="btn-primary" onclick="saveInfo()">保存</webui:button>
	</div>
</webui:panel>

<script>
	var editInfoSaveBtn = $("#editInfoSaveBtn").ladda();

	function editInfo(){
		$('#editInfoFaviconFile').fileinput('clear');
		$('#editInfoIconFile').fileinput('clear');
		$('#editInfoLogoFile').fileinput('clear');

 		$("#editInfoForm").reset();
		editInfoFormValidator.resetForm()
		editInfoSaveBtn.ladda('stop');
		$("#listInfo").hide();
 		$("#editInfo").show();
		
		$.ajax({
 	 	    type:"GET",
 	 	    async:false,
 	 	    url:"${contextPath}/rest/mgmtInfoes/search/findFirstOrDeFault",
 	 	    success:function(info){
 	 	 	    if(info!=null){
 	 	 	    	$("#editInfoId").val(info.id);
 	 	 	    	//$("#editInfoHeader").val(info.header);
 	 	 	    	$("#editInfoTitle").val(info.title);
 	 	 	    	$("#editInfoSubTitle").val(info.subTitle);
 	 	 	    	$("#editInfoCopyright").val(info.copyright);
 	 	 			$("#editInfoDefaultNav").val(info.defaultNav);
 	 	 			$("#editInfoDefaultNav").trigger("chosen:updated");
 	 	 	 	}	 	    	
 	 	    }
 	 	});
	}

	function saveInfo(){
		if(!editInfoFormValidator.form())
 	 		return;
		editInfoSaveBtn.ladda('start');

		var formData = new FormData($('#editInfoForm')[0]);
		$.ajax({
			url: "${contextPath}/sys/info/save.action",
			type: "POST",
		    contentType: false,
			processData: false,
			async:false,
			data: formData,
			success: function(data){
				if(data.result == 0){
					infoView.load();
	 	 	    	showMessage('',"修改成功");
				}else{
					showError('',"修改失败 : "+data.message);  			 	 	    		
				}
				cancelInfo();
			}
		});
	}

	function cancelInfo(){
		$('#editInfoFaviconFile').fileinput('clear');
		$('#editInfoIconFile').fileinput('clear');
		$('#editInfoLogoFile').fileinput('clear');

 		$("#editInfoForm").reset();
		editInfoFormValidator.resetForm()
		editInfoSaveBtn.ladda('stop');
		$("#listInfo").show();
 		$("#editInfo").hide();
	}
</script>